//
//  179. 最大数.swift
//  LeetCodeTrain
//
//  Created by rjb on 2021/9/1.
//  Copyright © 2021 rjb. All rights reserved.
//

import Foundation
class Solution179 {
    // 最大数
    // 实际上排序就可以了
    func largestNumber(_ nums: [Int]) -> String {
        var nums = nums
        nums.sort { a, b in
            let ab = "\(a)" + "\(b)"
            let ba = "\(b)" + "\(a)"
            return ab > ba
        }
        var result = ""
        if nums[0] == 0 {
            return "0"
        }
        for item in nums {
            result.append(String(item))
        }
        return result
    }
    
    static func test() {
        let solution = Solution179()
//        let nums = [3,30,34,5,9]
        let nums = [0, 0]
        let result = solution.largestNumber(nums)
        print(result)
    }
}
